package com.pay.utils;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Configurable;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class AliBaBaIdentity {

    public Map<String, Object> Identity(String name, String idCard) throws IOException {
        String url = "https://eid.shumaidata.com/eid/check";
        String appCode = "e4dc60026946444ca103bbacc31a3431";

        Map<String, String> params = new HashMap<>();
        params.put("idcard", idCard);
        params.put("name",name);

        OkHttpClient client = new OkHttpClient.Builder().build();
        FormBody.Builder formbuilder = new FormBody.Builder();
        Iterator<String> it = params.keySet().iterator();
        while (it.hasNext()) {
            String key = it.next();
            formbuilder.add(key, params.get(key));
        }
        FormBody body = formbuilder.build();
        Request request = new Request.Builder().url(url).addHeader("Authorization", "APPCODE " + appCode).post(body).build();
        Response response = client.newCall(request).execute();
        System.out.println("返回状态码" + response.code() + ",message:" + response.message());
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("code",response.code());
        resultMap.put("message",response.message());
        return resultMap;
    }
}
